<?php

function image_thumb( $image_path, $height, $width, $with_img = true ) {
    // Get the CodeIgniter super object
    $CI =& get_instance();
    
    $name_image = end(preg_split("[/]", $image_path));
    
    $ext = pathinfo($image_path, PATHINFO_EXTENSION);
    $name_image = basename($name_image, '.'.$ext);
    
    // Path to image thumbnail
    $image_thumb = 'data/Thumbnail/' . $name_image . '_' . $height . '_' . $width . '.'.$ext;

    if ( !file_exists( $image_thumb ) ) {
          if (!is_dir('data/Thumbnail/')) {
               mkdir('data/Thumbnail/');         
          }
        // LOAD LIBRARY
        $CI->load->library( 'image_lib' );

        // CONFIGURE IMAGE LIBRARY
        $config['image_library']    = 'gd2';
        $config['source_image']     = $image_path;
        $config['new_image']        = $image_thumb;
        $config['maintain_ratio']   = TRUE;
        $config['height']           = $height;
        $config['width']            = $width;
        $CI->image_lib->initialize( $config );
        $CI->image_lib->resize();
        $CI->image_lib->clear();
    }

//    return '<img src="' . "". '/' . $image_thumb . '" />';
	if($with_img == true)
    return '<img src="' . base_url($image_thumb) . '" />';
	elseif($with_img == false)
    return base_url($image_thumb);
}

/* End of file image_helper.php */
/* Location: ./application/helpers/image_helper.php */